import Vue from 'vue'
import VueRouter from 'vue-router'




import Login from "@/market_stall/Login";
import Home from "@/market_stall/Home";
import WelCome from "@/market_stall/WelCome";
import Stall from "@/market_stall/Stall";
import RentOrder from "@/lease/RentOrder";
import AuctionOrder from "@/lease/AuctionOrder";
import Contract from "@/lease/Contract";
import userList from '@/market_stall/user/userList'
import userClass from '@/market_stall/user/userClass'
import Department from "@/market_stall/system/Department";
import Log from "@/market_stall/system/Log";
import Manager from "@/market_stall/system/Manager";
import Role from "@/market_stall/system/Role";
import stallDetail from "@/market_stall/StallDetail";
import StallDetail from "@/market_stall/StallDetail";
import AuctionStall from "@/market_stall/AuctionStall";
import AuctionDetail from "@/market_stall/AuctionDetail";
import Market from "@/market_stall/Market";
import MarketDetail from "@/market_stall/MarketDetail";

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    name:'Login',
    component:Login
  },
  {
    path:'/Login',
    name:'Login',
    component:Login
  },
  {
    path:'/Home',
    name:'Home',
    component:Home,
    children:[
      {
        path:'/',
        name:'WelCome',
        component:WelCome
      },
      {
        path:'/log',
        name:'Log',
        component:Log
      },
      {
        path:'/role',
        name:'Role',
        component:Role
      },
      {
        path:'/dept',
        name:'Department',
        component:Department
      },
      {
        path:'/auctionList',
        name:'AuctionOrder',
        component:AuctionOrder
      },
      {
        path:'/userList',
        name:'userList',
        component:userList
      },

      {
        path:'/userClass',
        name:'userClass',
        component:userClass
      },
      {
        path:'/admin',
        name:'Manager',
        component:Manager
      },
      {
        path:'/rent',
        name:'rent',
        component:Stall
      },
      {
        path:'/rentList',
        name:'RentOrder',
        component:RentOrder
      },
      {
        path:'/auctionList',
        name:'AuctionOrder',
        component:AuctionOrder
      },
      {
        path:'/rentDetail',
        name:'rentDetail',
        component:StallDetail
      },
      {
        path:'/auction',
        name:'auction',
        component:AuctionStall
      },
      {
        path:'/contractList',
        name:'Contract',
        component:Contract
      },
      {
        path:'/market',
        name:'market',
        component:Market
      },
      {
        path:'/marketDetail',
        name:'marketDetail',
        component:MarketDetail
      },
      {
        path:'/auctionDetail',
        name:'auctionDetail',
        component:AuctionDetail
      },
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//在路由对象上添加 路由守卫  做用户登录权限认证   不安全 （所有前端的控制 都是不安全的）
/**
 * to : 包含你要访问的路由
 * from  ：你从哪个路由过来的对象
 * next  ：函数 控制你的访问
 */
router.beforeEach((to,from,next)=>{
  let toPath = to.path ;
  let fromPath = from.path ;
  console.log(toPath,fromPath);
  if (toPath == '/' || toPath == '/Login') {
    //放行
    next() ;// 放行
  }else {
    // 其他路由 需要登录 才可以访问
    let  manager = sessionStorage.getItem("managerInfo");
    if (manager) {
      next() ;// 放行
    }else  {
      alert("请先登录!");
      //如果没有登录  转到 登录界面
      next("/Login")
    }
  }

})


export default router
